package ar.edu.itba.it.pdc.configuration.models.filters.destinyFilters;

import java.net.InetAddress;
import java.net.UnknownHostException;

import ar.edu.itba.it.pdc.configuration.models.Request;
import ar.edu.itba.it.pdc.monitoring.ProxyMonitoring;

public class DestinyIpFilter extends DestinyFilter {
	
	private InetAddress ip;
	
	public DestinyIpFilter(InetAddress ip) {
		this.ip = ip;
		setApplyOnRequest(true);
		setApplyOnResponse(false);
	}
	
	@Override
	public boolean applyFilterOnRequest(Request req) {

		try {
			if (!ip.equals(req.getDestinyIp())) {
				return true;
			}
			ProxyMonitoring.getInstance().addIpBlock();
			return false;
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
		return false;
	}
		
	@Override
	public String getContent() {
		return ip.toString();
	}
	
	@Override
	public String getCriteria() {
		return "IP";
	}
}
